// Find the element with an ID of 'main'
var obj = document.getElementById("main");

// Change it's border styling
obj.style.border = "1px solid red";

// Initialize a callback that will occur in one second
setTimeout(function(){
    // Which will hide the object
    obj.style.display = 'none';
}, 1000);

// A generic function for displaying a delayed console.log message
function delayedAlert( msg, time ) {
    // Initialize an enclosed callback
    setTimeout(function(){
        // Which utilizes the msg passed in from the enclosing function
        console.log( msg );
    }, time );
}

// Call the delayedAlert function with two arguments
delayedAlert( "Welcome!", 2000 );

function outer() {
	var x = 0;
	return function() {
		return ++x;
	};
}

var x=1000;
var f = new outer();
console.log(f()); // 1 출력
console.log(f()); // 2 출력

var g = new outer();
console.log(g());
console.log(g());

//http://blog.outsider.ne.kr/506
// window.onload = function() {
//     for(var i=1; i < 5; i++ ) {
//         document.getElementById("btn" + i).addEventListener("click", function() {
//             alert(i);
//         }, false);
//     }
// }
window.onload = function() {
	for(var i=1; i<5; i++) {
		(function(m) {
			document.getElementById("btn" + m).addEventListener("click", function() {
				console.log(m);
			}, false);
		}(i));
	}
}


// http://rhio.tistory.com/208
function outerFn() {
	var colsure = 'is Closure.';
	var private = 'this';

	return function(private) {
		console.log(private + ' ' + colsure);
	};
}

var func = outerFn(); // closure instance 생성자
func('function');
console.log(func.constructor);
var func = null; // instance 초기화